package cn.endowment;

import java.util.List;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.endowment.dao.IUserDao;
import cn.endowment.entry.User;

public class FenYeDemo {

	@Test
	public void testPageHelper() {
		Logger log=Logger.getLogger(FenYeDemo.class);
		// 创建一个spring容器
		ApplicationContext act = new ClassPathXmlApplicationContext("spring/spring.xml");
		// 从spring容器中获取mapper代理对象
		IUserDao mapper = act.getBean(IUserDao.class);
		//分页处理，显示第2页的5条数据
		PageHelper.startPage(2,5);
		//查询
		List<User> userList = mapper.queryUser();
		// 输出userList信息
		for(User user : userList) {
			log.debug(user.getName());
		}
		// 取分页信息
		PageInfo<User> pageInfo = new PageInfo<User>(userList);
		//获取总记录数
		long total = pageInfo.getTotal();	       
		log.debug("共有用户记录数" + total+"个");
	}

}
